﻿using System;
using System.Text;
using System.Collections;
using System.Collections.Generic;

namespace SBPweb.PhotoGallery.Common
{

    /// <summary>
    /// Summary description for PhotoGalleryViewerInfo
    /// </summary>
    public class Gallery : Gallery<Slide>

    {

        #region Constructor logic

        public Gallery()
            : base()
        {
        }

        public Gallery(string basePath)
            : base(basePath)
        {
        }

        public Gallery(Slide[] slides, string basePath)
            : base(slides, basePath)
        {
        }

        public Gallery(Slide[] slides, string basePath, int? pageIndex, int? pageSize)
            : base(slides, basePath, pageIndex, pageSize)
        {
        }

        #endregion

    }

    public class Gallery<TSlide> : OverridableList<TSlide>//, ICloneable
        where TSlide : Slide
    {
        
        #region Private fields

        private string pBasePath;
        private int? pPageIndex;
        private int? pPageSize;
        //private int pPhotoGalleryId;
        //private int pModuleId;
        private DateTime pCreatedDate;
        private string pTitle;
        private string pSource;

        private string pWidth = null;
        private string pHeight = null;
        private string pForeground = null;
        private string pBackground = null;
        private string pButtonBackground = null;
        private string pButtonForeground = null;
        private string pButtonBorder = null;
        private string pButtonPlayForeground = null;
        private string pCaptionBackground = null;
        private string pCaptionForeground = null;
        private string pContentBackground = null;
        private string pSelectedThumbnailBorder = null;
        private string pTrackerForeground = null;
        private decimal? pCaptionOpacity = null;
        private string pCaptionFont = null;
        private string pTrackerFont = null;
        private int? pBorderRadius = null;
        private int? pPadding = null;
        private bool? pCaptionVisible = null;
        private bool? pThumbnailsVisible = null;
        private bool? pTrackerVisible = null;
        private bool? pAutoPlay = null;

        #endregion

        #region Constructor logic

        public Gallery()
            : this(string.Empty)
        {
        }

        public Gallery(string basePath)
        {
            if (!string.IsNullOrEmpty(basePath))
            {
                pBasePath = basePath;
            }
            InitializeHandlers();
        }

        public Gallery(TSlide[] slides, string basePath)
            : this(basePath)
        {
            this.AddRange(slides);
        }

        public Gallery(TSlide[] slides, string basePath, int? pageIndex, int? pageSize)
            : this(slides, basePath)
        {
            if (pageIndex.HasValue)
            {
                PageIndex = pageIndex.Value;
            }
            if (pageSize.HasValue)
            {
                PageSize = pageSize.Value;
            }
        }

        ~Gallery()
        {
            FinalizeHandlers();
        }

        protected virtual void InitializeHandlers()
        {
        }

        protected virtual void FinalizeHandlers()
        {
        }

        #endregion

        #region Property accessors

        //public int PhotoGalleryId
        //{
        //    get
        //    {
        //        return pPhotoGalleryId;
        //    }
        //    set
        //    {
        //        pPhotoGalleryId = value;
        //    }
        //}

        //public int ModuleId
        //{
        //    get
        //    {
        //        return pModuleId;
        //    }
        //    set
        //    {
        //        pModuleId = value;
        //    }
        //}

        public string Title
        {
            get
            {
                return pTitle;
            }
            set
            {
                pTitle = value;
            }
        }

        public string Source
        {
            get
            {
                return pSource;
            }
            set
            {
                pSource = value;
            }
        }

        public string BasePath
        {
            get
            {
                return pBasePath;
            }
            set
            {
                pBasePath = value;
            }
        }

        public int? PageIndex
        {
            get
            {
                return pPageIndex;
            }
            set
            {
                pPageIndex = value;
            }
        }

        public int? PageSize
        {
            get
            {
                return pPageSize;
            }
            set
            {
                pPageSize = value;
            }
        }

        public DateTime CreatedDate
        {
            get
            {
                return pCreatedDate;
            }
            set
            {
                pCreatedDate = value;
            }
        }
        
        public string Width
        {
            get
            {
                return pWidth;
            }
            set
            {
                pWidth = value;
            }
        }

        public string Height
        {
            get
            {
                return pHeight;
            }
            set
            {
                pHeight = value;
            }
        }

        public string Background
        {
            get
            {
                return pBackground;
            }
            set
            {
                pBackground = value;
            }
        }

        public string Foreground
        {
            get
            {
                return pForeground;
            }
            set
            {
                pForeground = value;
            }
        }

        public string ButtonBackground
        {
            get
            {
                return pButtonBackground;
            }
            set
            {
                pButtonBackground = value;
            }
        }

        public string ButtonForeground
        {
            get
            {
                return pButtonForeground;
            }
            set
            {
                pButtonForeground = value;
            }
        }

        public string ButtonBorder
        {
            get
            {
                return pButtonBorder;
            }
            set
            {
                pButtonBorder = value;
            }
        }

        public string ButtonPlayForeground
        {
            get
            {
                return pButtonPlayForeground;
            }
            set
            {
                pButtonPlayForeground = value;
            }
        }

        public string CaptionBackground
        {
            get
            {
                return pCaptionBackground;
            }
            set
            {
                pCaptionBackground = value;
            }
        }

        public string CaptionForeground
        {
            get
            {
                return pCaptionForeground;
            }
            set
            {
                pCaptionForeground = value;
            }
        }

        public string ContentBackground
        {
            get
            {
                return pContentBackground;
            }
            set
            {
                pContentBackground = value;
            }
        }

        public string SelectedThumbnailBorder
        {
            get
            {
                return pSelectedThumbnailBorder;
            }
            set
            {
                pSelectedThumbnailBorder = value;
            }
        }

        public string TrackerForeground
        {
            get
            {
                return pTrackerForeground;
            }
            set
            {
                pTrackerForeground = value;
            }
        }

        public decimal? CaptionOpacity
        {
            get
            {
                return pCaptionOpacity;
            }
            set
            {
                pCaptionOpacity = value;
            }
        }

        public string CaptionFont
        {
            get
            {
                return pCaptionFont;
            }
            set
            {
                pCaptionFont = value;
            }
        }

        public string TrackerFont
        {
            get
            {
                return pTrackerFont;
            }
            set
            {
                pTrackerFont = value;
            }
        }

        public int? BorderRadius
        {
            get
            {
                return pBorderRadius;
            }
            set
            {
                pBorderRadius = value;
            }
        }

        public int? Padding
        {
            get
            {
                return pPadding;
            }
            set
            {
                pPadding = value;
            }
        }

        public bool? CaptionVisible
        {
            get
            {
                return pCaptionVisible;
            }
            set
            {
                pCaptionVisible = value;
            }
        }

        public bool? ThumbnailsVisible
        {
            get
            {
                return pThumbnailsVisible;
            }
            set
            {
                pThumbnailsVisible = value;
            }
        }

        public bool? TrackerVisible
        {
            get
            {
                return pTrackerVisible;
            }
            set
            {
                pTrackerVisible = value;
            }
        }

        public bool? AutoPlay
        {
            get
            {
                return pAutoPlay;
            }
            set
            {
                pAutoPlay = value;
            }
        }

        #endregion

        #region Methods

        public object Clone()
        {
            return Clone(0, this.Count);
        }

        public Gallery<TSlide> Clone(int index, int count)
        {
            Gallery<TSlide> slides = new Gallery<TSlide>(BasePath);
            slides.AddRange(this.GetRange(index, count));
            return slides;
        }

        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendFormat("<slides baseUrl=\"{0}\"", BasePath);
            if (PageIndex.HasValue)
            {
                sb.AppendFormat(" page=\"{0}\"", PageIndex.Value);
            }
            if (PageSize.HasValue)
            {
                sb.AppendFormat(" pageSize=\"{0}\"", PageSize.Value);
            }
            sb.AppendLine(">");
            foreach (Slide slide in this)
            {
                sb.AppendLine(slide.ToString());
            }
            sb.Append("</slides>");
            return sb.ToString();
        }

        #endregion

    }
    
}